# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=jsonrpc-server
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.4.0
pkgrel=3
pkgdesc="Python library implementing asynchronous JSON RPC server (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/palantir/python-jsonrpc-server"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-future"
         "${MINGW_PACKAGE_PREFIX}-python-ujson")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-coverage"
              "${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
              "${MINGW_PACKAGE_PREFIX}-python-pyflakes"
              "${MINGW_PACKAGE_PREFIX}-python-mock")
source=("python-${_realname}-${pkgver}.tar.gz"::"${url}/archive/${pkgver}.tar.gz"
        "001-python-jsonrpc-server-0.4.0-fix-versioneer.patch"
        "002-python-jsonrpc-server-0.4.0-fix-test.patch")
sha256sums=('d2ca9d2fa0ae5f3872f1362670509d8ee5e73cad0592c3c23390c4d521b30b8b'
            '816e9fc00654e21a9086a57797ddaf0c0056ca74bc32653d3b42a9152b94117a'
            '417deed5e3bf6c04868bb7c567f664c40be8a400dabc6594d593d803d292a7ce')

prepare() {
  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "python-${_realname}-${pkgver}" "python-build-${CARCH}"
  cd "python-build-${CARCH}"
  patch -p1 -i "${srcdir}/001-python-jsonrpc-server-0.4.0-fix-versioneer.patch"
  patch -p1 -i "${srcdir}/002-python-jsonrpc-server-0.4.0-fix-test.patch"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  VERSIONEER_OVERRIDE=${pkgver} \
    ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  PYTHONPATH="build/lib" pytest
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  VERSIONEER_OVERRIDE=${pkgver} \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}

# vim: ts=2 sw=2 et:
